import Taro, {Component} from '@tarojs/taro'
import { AtCard,AtInput,AtTextarea ,AtButton,AtMessage} from "taro-ui"
import {View} from "@tarojs/components"
import {toast,showErrorMsg} from "../../../utils";
import {saveFeedback} from "./service";
import './index.scss'

export default class Index extends Component {
  config = {
    navigationBarTitleText:'反馈'
  }
    constructor(props) {
        super(props);
        this.state = {
          concat: '',
          feedBack:''
        }
    }
  concatChange (value) {
    this.setState({
      concat:value
    })
    return value
  }
  feedbackChange(event){
    this.setState({
      feedBack: event.target.value
    })
  }
  submitFeedback(){
    let {concat,feedBack} = this.state
    if(concat===''){
      showErrorMsg('请留下您的联系方式')
      return
    }
    if(feedBack===''){
      showErrorMsg('反馈内容不能为空')
      return
    }
    toast('您的反馈已提交，感谢支持')
    saveFeedback(concat,feedBack)
  }
    render() {

        return (
            <View>
              <AtCard
                title='联系方式'
              >
                <AtInput
                  name='concat'
                  placeholder='微信、邮箱、QQ等'
                  value={this.state.concat}
                  onChange={this.concatChange.bind(this)}
                  focus={true}
                />
              </AtCard>
              <AtCard
                title='反馈内容'
              >
                <AtTextarea
                  value={this.state.feedBack}
                  onChange={this.feedbackChange.bind(this)}
                  maxLength={500}
                  placeholder='反馈内容...'
                />
              </AtCard>
              <AtButton type='primary'
                onClick={this.submitFeedback.bind(this)}
                className="button_bottom"
              >提交反馈</AtButton>
              <AtMessage />
            </View>
        )
    }

}
